Public Class TemplateItem
  Private _insert As String = String.Empty
  Private _title As String = String.Empty
  Private _category As String = String.Empty
  Private _iconfile As String = "%SystemRoot%\system32\shell32.dll"
  Private _iconindex As Integer = 1
  Private _templatePath As String = String.Empty

  Public Property Title() As String
    Get
      Return _title
    End Get
    Set(ByVal value As String)
      _title = value
    End Set
  End Property

  Public Property Insert() As String
    Get
      Return _insert
    End Get
    Set(ByVal value As String)
      _insert = value
    End Set
  End Property

  Public Property TemplateFilePath() As String
    Get
      Return _templatePath
    End Get
    Set(ByVal value As String)
      _templatePath = value
    End Set
  End Property

  Public Property Category() As String
    Get
      Return _category
    End Get
    Set(ByVal value As String)
      _category = value
    End Set
  End Property

  Public Property IconFile() As String
    Get
      Return _iconfile
    End Get
    Set(ByVal value As String)
      _iconfile = value
    End Set
  End Property

  Public Property IconIndex() As Integer
    Get
      Return _iconindex
    End Get
    Set(ByVal value As Integer)
      _iconindex = value
    End Set
  End Property

  Public ReadOnly Property Icon() As System.Drawing.Icon
    Get
      Dim ic As System.Drawing.Icon = ExtractIcon.GetIcon(_iconfile, _iconindex)
      Return ic

    End Get
  End Property

  <System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Globalization", "CA1304:SpecifyCultureInfo", MessageId:="System.String.ToUpper")> _
  Public Sub Load(ByVal textTemplateFilePath As String)
    _templatePath = TextTemplateFilePath

    Dim xml As New Xml.XmlDocument
    xml.Load(_templatePath)

    Dim xmlNL As Xml.XmlNodeList
    xmlNL = xml.GetElementsByTagName("wlwtexttemplate")
    Dim n As Xml.XmlNode
    Dim e As Xml.XmlElement

    For Each n In xmlNL

      For Each e In n

        Select Case e.Name.ToUpper
          Case "TITLE"
            _title = e.InnerText

          Case "INSERT"
            _insert = e.InnerText

          Case "CATEGORY"
            _category = e.InnerText

          Case "ICON"
            _iconfile = e.InnerText
            _iconindex = e.Attributes(0).InnerText
        End Select

      Next e

    Next n

  End Sub

  Public Sub Save()
    Dim xb As New System.Text.StringBuilder
    xb.Append("<wlwtexttemplate>")
    xb.Append("<title><![CDATA[")
    xb.Append(_title)
    xb.Append("]]></title>")

    xb.Append("<category><![CDATA[")
    xb.Append(_category)
    xb.Append("]]></category>")

    xb.Append("<icon iconindex=")
    xb.Append(Chr(34))
    xb.Append(_iconindex)
    xb.Append(Chr(34))
    xb.Append("><![CDATA[")
    xb.Append(_iconfile)
    xb.Append("]]></icon>")

    xb.Append("<insert><![CDATA[")
    xb.Append(_insert)
    xb.Append("]]></insert>")
    xb.Append("</wlwtexttemplate>")

    My.Computer.FileSystem.WriteAllText(_templatePath, xb.ToString, False)

  End Sub

End Class
